const express = require('express');
const mysql = require('mysql');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const consolidate = require('consolidate');
const multer = require('multer');
const bodyParser = require('body-parser');

// multer上传数据
const multerObj = multer({dest:'./static/upload'});

const server = express();
server.listen(8088);

// 请求数据
server.use(bodyParser.urlencoded({extended:false}));
server.use(multerObj.any());


// cookie session
let keys = [];
for (let index = 0; index < 10000; index++) {
    keys.push('key_'+Math.random());
}
server.use(cookieParser());
server.use(cookieSession({
    name:'blog_id',
    keys:keys,
    maxAge:20*60*1000
}))
// 模板
server.engine('html', consolidate.ejs);
server.set('views', './template');
server.set('view engine', 'html');
// 后台路由
server.use('/admin',require('./route/admin/index')());
// web路由
server.use('/',require('./route/web/index')());
// 静态文件
server.use(express.static('static'));